import './public-path'
import Vue from 'vue'
import App from './App.vue'
import VueRouter from "vue-router";
import {routes} from "./router";
import store from './store'
import ViewUI from 'view-design'
import '../../common/css/reset.css'
import 'view-design/dist/styles/iview.css';
Vue.config.productionTip = false
Vue.use(VueRouter)
let router = null
let instance = null
function render(props = {}) {
  const { container } = props
  router = new VueRouter({
    base: window.__POWERED_BY_QIANKUN__ ? '/#/vue-admin/' : '/',
    mode: 'hash',
    routes,
  })
  instance = new Vue({
    router,
    store,
    render: (h) => h(App)
  }).$mount(container ? container.querySelector('#app') : '#app')
}

//独立运行
if(!window.__POWERED_BY_QIANKUN__){
  render()
}

// if (inBrowser&& window.Vue) {
//   window.Vue.use(VueRouter);
// }

//只会在微应用初始化的时候调用一次，下次微应用重新进入时会直接调用mount钩子
export async function bootstrap() {
  console.log('admin项目初始化')
}

//引用每次进入都会调用mount方法，通常我们在这里触发应用的渲染方法
export async function mount(props){
  console.log('触发admin-mount')
  props.onGlobalStateChange((state,prev) => {
    console.log(state, prev);
  })
  console.log(props)
  render(props)
}

//应用每次切出/载入会调用的方法、通常这里我们会卸载微应用的应用实例
export async function unmount(props){
  console.log('触发admin-unmount卸载')
  instance.$destroy();
  instance.$el.innerHTML = '';
  instance = null;
  router = null
}

//可选的生命周期钩子，仅使用loadMicroApp方式加载微应用时生效
export async function update(props){
  console.log('触发admin-update')
}

